package com.itany.corejava.code14_lambda;

import java.util.Arrays;
import java.util.List;
import java.util.function.Supplier;

/**
 * @author 石小俊
 * @date 2023年05月30日 15:57
 */
public class Test03_供给型接口 {

    public static void main(String[] args) {
        // 匿名内部类方式
        List<String> list = testSupplier(new Supplier<List<String>>() {
            @Override
            public List<String> get() {
                return Arrays.asList("孙尚香", "蔡文姬", "貂蝉", "吕布", "赵云");
            }
        });
        System.out.println(list);

        // Lambda表达式
        List<String> list2 = testSupplier(() -> Arrays.asList("孙尚香", "蔡文姬", "貂蝉", "吕布", "赵云"));
        System.out.println(list2);
    }


    /**
     * 供给型接口Supplier<T>,方法:T get();
     * 接口有返回值,其接口泛型类型与方法返回值类型一致
     * @param supplier
     * @return
     */
    public static List<String> testSupplier(Supplier<List<String>> supplier) {
        return supplier.get();
    }

}
